#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}

wget -O "$HOME/linuxcnc.deb" https://www.linuxcnc.org/dists/buster/2.8-rtpreempt/binary-armhf/linuxcnc-uspace_2.8.1_armhf.deb || error 'Failed to download LinuxCNC deb!'
"${DIRECTORY}/pkg-install" "$HOME/linuxcnc.deb" "$(dirname "$0")" || error 'Failed to install LinuxCNC deb with pkg-install!'
rm -f "$HOME/linuxcnc.deb"

#move all desktop files to the Programming category
find /usr/share/applications -type f -name 'linuxcnc*' | xargs sudo sed -i 's/Categories=.*/Categories=Development;/g'
